package cn.iocoder.yudao.module.english.service.reward;

import cn.iocoder.yudao.module.english.controller.admin.reward.vo.RewardConfigurationPageReqVO;
import cn.iocoder.yudao.module.english.controller.admin.reward.vo.RewardConfigurationSaveReqVO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.module.english.dal.dataobject.reward.RewardConfigurationDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.english.dal.mysql.reward.RewardConfigurationMapper;

import javax.annotation.Resource;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
//import static cn.iocoder.yudao.module.english.enums.ErrorCodeConstants.*;

/**
 * 奖励配置 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class RewardConfigurationServiceImpl implements RewardConfigurationService {

    @Resource
    private RewardConfigurationMapper rewardConfigurationMapper;

    @Override
    public Long createRewardConfiguration(RewardConfigurationSaveReqVO createReqVO) {
        // 插入
        RewardConfigurationDO rewardConfiguration = BeanUtils.toBean(createReqVO, RewardConfigurationDO.class);
        rewardConfigurationMapper.insert(rewardConfiguration);
        // 返回
        return rewardConfiguration.getId();
    }

    @Override
    public void updateRewardConfiguration(RewardConfigurationSaveReqVO updateReqVO) {
        // 校验存在
        validateRewardConfigurationExists(updateReqVO.getId());
        // 更新
        RewardConfigurationDO updateObj = BeanUtils.toBean(updateReqVO, RewardConfigurationDO.class);
        rewardConfigurationMapper.updateById(updateObj);
    }

    @Override
    public void deleteRewardConfiguration(Long id) {
        // 校验存在
        validateRewardConfigurationExists(id);
        // 删除
        rewardConfigurationMapper.deleteById(id);
    }

    private void validateRewardConfigurationExists(Long id) {
        if (rewardConfigurationMapper.selectById(id) == null) {
//            throw exception(REWARD_CONFIGURATION_NOT_EXISTS);
        }
    }

    @Override
    public RewardConfigurationDO getRewardConfiguration(Long id) {
        return rewardConfigurationMapper.selectById(id);
    }

    @Override
    public PageResult<RewardConfigurationDO> getRewardConfigurationPage(RewardConfigurationPageReqVO pageReqVO) {
        return rewardConfigurationMapper.selectPage(pageReqVO);
    }

}